package com.fwtai.api.controller;

import com.fwtai.config.ConfigFile;
import com.fwtai.entity.ReqPage;
import com.fwtai.service.api.ApiUserAddressService;
import com.fwtai.tool.ToolClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 用户收货地址控制层|路由层[api]
 * @作者 李宇鹏
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-06-28 11:07:53
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@Api(tags = "用户收货地址",description = "token选填")
@RequestMapping(ConfigFile.guest_v10 +"userAddress")
public class UserAddressController {

  private final ApiUserAddressService apiUserAddressService;

  public UserAddressController(final ApiUserAddressService apiUserAddressService){
    this.apiUserAddressService = apiUserAddressService;
  }

  /**添加*/
  @ApiOperation(value = "添加用户收货地址", notes = "新建|新增|添加操作,bean实体form表单方式非json格式提交")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "real_name", value = "收货人姓名,限制长度30个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "phone", value = "收货人联系方式,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "defaults", value = "是否为默认地址（1是，0否）,限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_id", value = "省主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_name", value = "省名称,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_id", value = "市主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_name", value = "市名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_id", value = "区县kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_name", value = "区县名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "address", value = "详细地址,限制长度128个", dataType = "String", paramType = "query", required = true),
  })
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.add(request),response);
  }

  /**编辑*/
  @ApiOperation(value = "编辑用户收货地址", notes = "通过主键kid编辑|修改数据,字段的参照表结构，主键的字段可能不是id或kid,请参考表结构")
  @ApiImplicitParams({
    @ApiImplicitParam(name = "kid", value = "被修改的主键值,其余的参照表结构", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "real_name", value = "收货人姓名,限制长度30个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "phone", value = "收货人联系方式,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "defaults", value = "是否为默认地址（1是，0否）,限制长度1个", dataType = "int", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_id", value = "省主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "province_name", value = "省名称,限制长度40个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_id", value = "市主键kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "city_name", value = "市名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_id", value = "区县kid,限制长度20个", dataType = "long", paramType = "query", required = true),
    @ApiImplicitParam(name = "county_name", value = "区县名称,限制长度20个", dataType = "String", paramType = "query", required = true),
    @ApiImplicitParam(name = "address", value = "详细地址,限制长度128个", dataType = "String", paramType = "query", required = true),
  })
  @PostMapping("/edit")
  public void edit(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.edit(request),response);
  }

  /**根据主键kid查询对应的数据*/
  @ApiOperation(value = "获取单条的用户收货地址详细信息", notes = "通过主键kid获取用户收货地址详细信息")
  @ApiImplicitParam(name = "id", value = "被查看的kid", dataType = "String", paramType = "query", required = true)
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.queryById(id),response);
  }

  /**删除-单行*/
  @ApiOperation(value = "删除单条用户收货地址数据", notes = "通过id删除对应用户收货地址数据")
  @ApiImplicitParam(name = "id", value = "根据主键kid删除对应的数据", dataType = "String", paramType = "query", required = true)
  @PostMapping("/delById")
  public void delById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.delById(id),response);
  }

  /**批量删除*/
  @ApiOperation(value = "批量删除用户收货地址数据", notes = "通过ids集合删除对应数据,ids是字符串集合,每个值主键kid以英文逗号,隔开;格式如10001,10002,10003")
  @ApiImplicitParam(name = "ids", value = "主键的集合以英文逗号,隔开。如10001,10002,10003", dataType = "String", paramType = "query", required = true)
  @PostMapping("/delByKeys")
  public void delByKeys(final String ids,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.delByKeys(ids),response);
  }

  /**获取分页数据*/
  @ApiOperation(value = "获取用户收货地址分页数据,默认仅含数据不含总记录数总条数", notes = "其参数是搜索过滤条件;defaults是否为默认地址（1是，0否）;排序的key为column值为返回的字段，排序关键字的key为order,其值可选正序ASC|倒序DESC<br/>注意调用端需要判断每次请求返回的条数是否小于每页大小或返回的code=201而停止下一次请求")
  @GetMapping("/listDataPage")
  public void listDataPage(final ReqPage reqPage,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.listData(request),response);
  }

  /**获取用户默认收获地址*/
  @ApiOperation(value = "获取用户默认收获地址", notes = "获取登录用户默认收获地址")
  @GetMapping("/getDefaultAddress")
  public void listDataPage(final HttpServletResponse response){
    ToolClient.responseJson(apiUserAddressService.getDefaultAddress(),response);
  }
}